package com.gwnet.shop.controller;

import java.util.List;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gwnet.common.log.annotation.Log;
import com.gwnet.common.log.enums.BusinessType;
import com.gwnet.common.mybatis.core.page.TableDataInfo;
import com.gwnet.common.satoken.utils.LoginHelper;
import com.gwnet.shop.utils.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gwnet.shop.domain.FeeStandard;
import com.gwnet.shop.service.IFeeStandardService;
import javax.annotation.Resource;

/**
 * 配送费用收费标准Controller
 * @author zhangwanpeng
 * @date 2024-08-06
 */
@RestController
@RequestMapping("/feestandard")
public class FeeStandardController extends MBaseController
{
    @Resource
    private IFeeStandardService feeStandardService;

    /**
     * 查询配送费用收费标准列表
     */
    @SaCheckPermission("shop:feestandard:list")
    @GetMapping("/list")
    public TableDataInfo list(FeeStandard feeStandard)
    {
        startPage();
        List<FeeStandard> list = feeStandardService.selectFeeStandardList(feeStandard);
        return getDataTable(list);
    }


    /**
     * 获取配送费用收费标准详细信息
     */
    @SaCheckPermission("shop:feestandard:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(feeStandardService.selectFeeStandardById(id));
    }

    /**
     * 新增配送费用收费标准
     */
    @SaCheckPermission("shop:feestandard:add")
    @Log(title = "配送费用收费标准", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FeeStandard feeStandard)
    {
        feeStandard.setCreateBy( LoginHelper.getUserId() );
        return toAjax(feeStandardService.insertFeeStandard(feeStandard));
    }

    /**
     * 修改配送费用收费标准
     */
    @SaCheckPermission("shop:feestandard:edit")
    @Log(title = "配送费用收费标准", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FeeStandard feeStandard)
    {
        feeStandard.setCreateBy( LoginHelper.getUserId() );
        return toAjax(feeStandardService.updateFeeStandard(feeStandard));
    }

    /**
     * 删除配送费用收费标准
     */
    @SaCheckPermission("shop:feestandard:remove")
    @Log(title = "配送费用收费标准", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(feeStandardService.deleteFeeStandardByIds(ids));
    }


    /**
     * 根据订单金额查询 平台的配送费用
     * @param money
     * @return
     */
    @SaCheckPermission("shop:feestandard:query")
    @GetMapping(value = "/delivery/{money}")
    public AjaxResult getDeliveryAmount(@PathVariable Double money) {
        return success(feeStandardService.getDeliveryAmount(money));
    }
}
